﻿using System;
using System.Collections.Generic;
using Basic.Model.Entity;
using NHibernate;
using NHibernate.Criterion;

namespace Basic.Model.EntityManager
{
    public class DictionaryTypeManager
    {
        public static void Add(ISession session, DictionaryType an)
        {
            session.Save(an);
        }

        public static void Update(ISession session, DictionaryType an)
        {
            session.Update(an);
        }

        public static DictionaryType Get(ISession session, int itemId)
        {
            return session.Get<DictionaryType>(itemId);
        }

        public static DictionaryType GetByCondition(ISession session, string dictionaryTypeName, bool isDictionarys)
        {
            ICriteria c = session.CreateCriteria(typeof(DictionaryType));
            c.Add(Expression.Eq("dictionaryTypeName", dictionaryTypeName));
            if (isDictionarys)
            {
                ICriteria c1 = c.CreateCriteria("dictionarys", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
                c1.AddOrder(Order.Asc("dictionaryOrderNumber"));
                c.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity);
            }
            return c.UniqueResult<DictionaryType>();
        }
    }
}
